(define (rand-update y)
    (remainder (+ 7 (* 3 y)) 1312)
)

(define rand 
    (let ((x 123))     
    (lambda (m) 
        (cond 
            ((eq? m `generate)
                (lambda () 
                    (set! x (rand-update x))
                    x
                )
            )
            ((eq? m `reset)
                (lambda (value) 
                    (set! x value)
                    (set! x (rand-update x))
                    x
                )
            )
            (else (error "..." m))
        )
    )
    )       
)


(display ((rand `generate)))
(newline)
((rand `reset) 456)
(newline)
(display ((rand `generate)))
(exit)